/*
 * @Date: 2021-09-11 09:29:31
 * @Author: Acckno1
 * @LastEditTime: 2021-09-11 09:51:03
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1010;

unordered_map<int, int> l, r;
int n;
int nums[N];
vector<int> path;

void dfs(int u) {
    path.push_back(u);
    if (!l.count(u) && !r.count(u)) {
        cout << path[0];
        for (int i = 1; i < path.size(); i ++ ) cout << " " << path[i];
        cout << endl;
        path.pop_back();
        return;
    }

    if (r.count(u)) dfs(r[u]);
    if (l.count(u)) dfs(l[u]);

    path.pop_back();
}

inline void solution() {
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> nums[i];
    
    int flag = nums[1] > nums[2] ? 1 : -1;
    for (int i = 1; i <= n / 2; i ++ ) {
        if (i * 2 <= n) 
            l[nums[i]] = nums[i * 2];
        if (i * 2 + 1 <= n) 
            r[nums[i]] = nums[i * 2 + 1];
        if (flag == 1 && (nums[i] < nums[i * 2] || (i * 2 + 1) <= n && nums[i] < nums[i * 2 + 1])) flag = 0;
        if (flag == -1 && (nums[i] > nums[i * 2] || (i * 2 + 1) <= n && nums[i] > nums[i * 2 + 1])) flag = 0;
    }
    
    dfs(nums[1]);

    if (flag == 0) cout << "Not Heap\n";
    else if (flag == 1) cout << "Max Heap\n";
    else cout << "Min Heap\n";
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}